package com.shuangti.webdemo.servvice.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shuangti.webdemo.mapper.DeptMapper;
import com.shuangti.webdemo.po.Dept;
import com.shuangti.webdemo.dto.DeptDto;
import com.shuangti.webdemo.servvice.DeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class DeptServiceImpl extends ServiceImpl<BaseMapper<Dept>,Dept> implements DeptService {
   private final DeptMapper deptMapper;


   @Override
   public List<Dept> selectDeptList() {

      List<Dept> depts = deptMapper.selectList(null);
      return depts;
   }
   /**
    * 根据id删除部门信息
    */
   @Override
   public void DeleById(Integer id) {
      deptMapper.deleteById(id);
   }

   /**
    * 添加部门
    */
   @Override
   public void addOne(DeptDto deptDto) {
      Dept dept = new Dept();
      dept.setCreateTime(LocalDateTime.now());
      dept.setUpdateTime(LocalDateTime.now());
      BeanUtil.copyProperties(deptDto,dept);
      saveOrUpdate(dept);
   }


}
